using ACompany.OrderProcessing.Infrastructure;

namespace ACompany.OrderProcessing.Model
{
    public class Item : BusinessBase<Item>
    {
        #region fields
        public Order Order { get; set; }
        public Product Product { get; set; }
        public int Qty { get; set; }
        public decimal Price { get; set; }
        #endregion

        protected override void Validate()
        {
            if (!(this.Qty > 0))
                this.BrokenRules.Add( new BrokenRule("Qty", "An item qty must be greater than 0."));

            if (Order == null)
                this.BrokenRules.Add( new BrokenRule("order","An item must have a parent order."));

            if (Product == null)
                this.BrokenRules.Add(new BrokenRule("Product", "An item contain a product."));

            if (!(Price > 0))
                this.BrokenRules.Add(new BrokenRule("Price", "The price of a product must be greater than 0."));
        }
        
    }
}